/*******************************************************************************
 * Copyright 2011-2012 Dik Grapendaal
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package sh.grapendaal.tsuushin.tracking;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

public class Network {
	private Map<String, TrackedChannel> channels = new HashMap<String, TrackedChannel>();
	private Map<String, TrackedUser> users = new HashMap<String, TrackedUser>();
	
	public void addChannel(TrackedChannel channel) {
		channels.put(channel.getName().toLowerCase(Locale.getDefault()), channel);
	}
	
	public boolean hasChannel(String name) {
		return channels.containsKey(name.toLowerCase(Locale.getDefault()));
	}
	
	public boolean removeChannel(String name) {
		String lowerName = name.toLowerCase(Locale.getDefault());
		if (channels.containsKey(lowerName)) {
			channels.remove(lowerName);
			return true;
		}
		
		return false;
	}
	
	public Map<String, TrackedChannel> getChannels() {
		return channels;
	}
	
	public TrackedChannel getChannel(String name) {
		String lowerName = name.toLowerCase(Locale.getDefault());
		if (channels.containsKey(lowerName)) {
			return channels.get(lowerName);
		}
		
		return null;
	}
	
	public void addUser(TrackedUser user) {
		users.put(user.getNickname().toLowerCase(Locale.getDefault()), user);
	}
	
	public boolean hasUser(String nickname) {
		return users.containsKey(nickname.toLowerCase(Locale.getDefault()));
	}
}
